//
//  Photo Viewer.m
//  HuiWenMovie
//
//  Created by ios on 15/7/23.
//  Copyright (c) 2015年 ios. All rights reserved.
//

#import "Photo Viewer.h"
#define kwth [UIScreen mainScreen].bounds.size.width
#define kheight [UIScreen mainScreen].bounds.size.height

@interface Photo_Viewer ()

@end

@implementation Photo_Viewer

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(kwth, 400);
    layout.minimumInteritemSpacing = 10;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    _photoView = [[PhotoView alloc]initWithFrame:CGRectMake(0, 0, kwth+10, kheight) collectionViewLayout:layout];
    _photoView.imageStringOfUrl = _imageUrl;
    _photoView.pagingEnabled = YES; 
    [self.view addSubview:_photoView];
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_currentIndex inSection:0];
    
    [_photoView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(singleAction) name:@"HideNavigationBar" object:nil];
    
    // Do any additional setup after loading the view.
}

- (void)singleAction
{
    BOOL isHidden = self.navigationController.navigationBarHidden;
    
    [self.navigationController setNavigationBarHidden:!isHidden animated:YES];
}

- (void)cancelAction
{
    [self dismissViewControllerAnimated:YES completion:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
